package uiLayer;

import java.util.Scanner;

import controllerLayer.LoanCtr;

public class ProductsForLeaseUI {
	
	private LoanCtr lctr; 
	private static ProductsForLeaseUI instance = null;

public ProductsForLeaseUI() {
	lctr = new LoanCtr();
}	
	
	public static ProductsForLeaseUI getInstance()       
	{
		if(instance == null)
		{
			instance = new ProductsForLeaseUI();
		}
		return instance;
	}
	
	public void loanMenuStart() {
		boolean exit = false;
		while(!exit){
		int choice = printLoanMenu();
		switch(choice)
		{
		 case 1: createPFL();
         break;
		 case 2: findByID();
         break;
		 case 3: updatePFL();
         break;
		 case 4: deletePFL();
		 break;
		 case 5: returnPFL();
         break;
		 case 6: goBack();
         break;
		}
		}
	}


	private void deletePFL() {
		Scanner keyboard = new Scanner(System.in); 
        System.out.print('\f');
        System.out.println("***Delete Product For Lease***");
        System.out.println("ID: ");
        int ID = InputParser.getInstance().parseInt(keyboard.nextLine());
        
        lctr.deleteProduct(ID);
		
	}

	private void goBack() {
		OfficeUI.getInstance().run();
		
	}

	private void updatePFL() {
		Scanner keyboard = new Scanner(System.in); 
        System.out.print('\f');
        System.out.println("***Update Product For Lease***");
        System.out.println("ID: ");
        int id = InputParser.getInstance().parseInt(keyboard.nextLine());
        System.out.println("Price: ");
        double price = InputParser.getInstance().parseDouble(keyboard.nextLine());
        System.out.println("Quantity: ");
        double quantity = InputParser.getInstance().parseDouble(keyboard.nextLine());
		lctr.updateLProduct(id, quantity, price);
		
	}

	private void findByID() {
		Scanner keyboard = new Scanner(System.in); 
        System.out.print('\f');
        System.out.println("***Find Product For Lease***");
        System.out.println("ID: ");
        int ID = InputParser.getInstance().parseInt(keyboard.nextLine());
        try{
        System.out.println(lctr.findLProduct(ID));
        }
        catch(NullPointerException npe){
			System.out.println("Product doesn't exist");
		}	
	}

	private void createPFL() {
		Scanner keyboard = new Scanner(System.in); 
        System.out.print('\f');
        System.out.println("***Create Product For Lease***");
        System.out.println("Name: ");
        String name = keyboard.nextLine();
        System.out.println("Description: ");
        String description = keyboard.nextLine();
        System.out.println("Category: ");
        String category = keyboard.nextLine();
        System.out.println("Price: ");
        double price = InputParser.getInstance().parseDouble(keyboard.nextLine());;
        System.out.println("Quantity: ");
        double quantity = InputParser.getInstance().parseDouble(keyboard.nextLine());
        String state = "available"; 
		lctr.createLItem(name, description, price, quantity, category, state);
		
	}
	
	
	public void returnPFL(){
		Scanner keyboard = new Scanner(System.in);
		System.out.println("Product ID:");
		int idProd = InputParser.getInstance().parseInt(keyboard.nextLine());
		
		lctr.returnProduct(idProd);
	}

	private int printLoanMenu() {
		Scanner keyboard = new Scanner(System.in);
	        System.out.print('\f');
	        System.out.println("*** Product For Lease Menu ***");
	        System.out.println("1. Create Product For Lease");
	        System.out.println("2. Find Product For Lease");
	        System.out.println("3. Update Product For Lease");
	        System.out.println("4. Delete Product For Lease");
	        System.out.println("5. Return Product");
	        System.out.println("6. Quit");
	        System.out.println("Your choice #: ");
	        
	        int choice = InputParser.getInstance().parseInt(keyboard.nextLine());
	        return choice;
	}


	
}